package com.example.back.controller;

import com.example.back.bean.GroupInfo;
import com.example.back.bean.GroupUser;
import com.example.back.dao.GroupDao;
import com.example.back.dao.GroupInfoDao;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/group")
public class GroupController {
    @Autowired
    private GroupDao groupDao;

    @Autowired
    private GroupInfoDao groupInfoDao;

    @RequestMapping("/selectId")
    public int selectId(int userId){
        GroupUser groupUser = groupDao.selectId(userId);
        if(groupUser!=null){
            return groupUser.getGroupId();
        }
        return -1;
    }

    @RequestMapping("/getAll")
    public List<GroupInfo> all(){
        return groupInfoDao.all();
    }

    @RequestMapping("/getOne")
    public GroupInfo one(int id){
        return groupInfoDao.one(id);
    }
}
